/**
 * Created by luojie on 2018/1/30.
 */
import "../css/radio.scss";

export default class Radio extends React.PureComponent{
	constructor(props){
		super(props);
		this.state = {
			checked:props.checked || false
		}
		this.onChange = this.onChange.bind(this);
	}
	onChange(){
		let {onChange} = this.props;
		onChange && onChange();
	}
	componentWillReceiveProps(nextProps){
		if(nextProps.checked !== this.props.checked){
			this.setState({
				checked:nextProps.checked
			})
		}
	}

	render(){
		let {checked} = this.state;
		let {label} = this.props;
		return(
			<button  onClick={this.onChange} className="inline-block pointer">
				<span className="comp-checkbox-wrapper">
					<span className={checked?"comp-checkbox checkbox-checked":"comp-checkbox"}>
					<span className="comp-checkbox-inner"/>
					</span>
					<span className="text-left">{label}</span>
				</span>

			</button>
		)
	}
}